package com.situ.mall.controller;

import com.situ.mall.pojo.Product;
import com.situ.mall.service.IProductService;
import com.situ.mall.util.JSONResult;
import com.situ.mall.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private IProductService productService;

    @RequestMapping("/getProductListPage")
    public String getProductListPage() {
        return "product_list";
    }

    // http://localhost:8080/product/selectByPage?page=1&limit=10
    @RequestMapping(value = "/selectByPage", method = RequestMethod.GET)
    @ResponseBody
    public LayUITableResult selectByPage(Integer page, Integer limit) {
        System.out.println("ProductController.selectByPage");
        LayUITableResult layUITableResult = productService.selectByPage(page, limit);
        return layUITableResult;
    }

    @RequestMapping("/getProductInsertPage")
    public String getProductInsertPage() {
        return "product_insert";
    }

    @RequestMapping("/insert")
    @ResponseBody
    public JSONResult insert(Product product) {
        return productService.insert(product);
    }
}
